﻿#region File Description
//  DomoBCI 
//  License: GNU/GPL
//  Developer: Federico Leonardo Motta
//  File description: This file comes from AEnima. Modified for C# socket comunications.
#endregion

#region Using Statements
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
#endregion

namespace DomoBCI.Core.Comunication
{
    public class BCIMessage
    {
        //Instrument control
        public const int	START_ACQ				=	101;
        public const int	STOP_ACQ				=	102;
        public const int CONNECTION_COMPLETED = 103;

        //Triggers event
        public const int GRAPH_TRIG = 201;

        //Messages from algorithm to AEnima
        public const int CLASSIFICATION = 301;
        public const int FEEDBACK = 302;
        public const int SET_PARAMS = 303;

        //Messagese from AEnima to algorithm
        public const int RESET_ALGORITHM = 401;
        public const int REQUEST_PARAMS = 402;

        //Generic messages
        public const int BCI_OK = 501;
        public const int BCI_ERROR = 502;

        //User
        public const int CREATE_USER = 601;
        public const int DELETE_USER = 602;
        public const int LOGIN = 603;

        //TODO: Inserire la costante relativa le 4 freq;

        /*!\struct BCIMessage
        \param kind Message type:\nSTART_ACQ, STOP_ACQ, CONNECTION_COMPLETED, GRAPH_TRIG, CLASSIFICATION, FEEDBACK, SET_PARAMS, RESET_ALGORITHM, REQUEST_PARAMS, BCI_OK, BCI_ERROR.\n
        For detail see AEnima overview.doc.
        \param value In some case it can be usefull to send and receive a value during the communication.
        \param Buffer The buffer can carry up to 16 int value.
        \param Check This value is used to control if the sent/received message is correct.*/
        public struct BCIMes
        {
            public int Kind;//Used to define which message you are sending
            public int Value;//Used for single value messages
            public int[] Buffer;//Storage space for DATA
            public int Check; //MS Kind+Value;
        }
        
        public BCIMes message;

        /*!\fn BCIMessage ComposeMessage(int Kind, int Value, int *pBuffer,int BuffSize)
        This function can be used to compose a BCIMessage*/
        public int Value = 0;
        public int[] pBuffer = new int[16];
        public int BuffSize=0;
        
        public BCIMes ComposeMessage(int Kind, int Value, int[] pBuffer,int BuffSize)
        {
	        BCIMes Ret = new BCIMes();
            Ret.Buffer = new int[16];
            for (int i = 0; i < Ret.Buffer.Length; i++ )
                Ret.Buffer[i] = 0;

	        Ret.Kind = Kind;
	        Ret.Value = Value;
	        Ret.Check = Kind+Value;
	        if(pBuffer.Length != 0 && BuffSize != 0)
                Ret.Buffer = pBuffer;

	        return Ret;
        }



        public BCIMessage() { }
    }
}
